const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const getRank = score => {
  let rankOBj = {
    rank: 1,
    rankName: '群众演员',
    max: 19
  };
  if(score > 0 && score <= 19) {
    rankOBj = {
      rank: 1,
      rankName: '群众演员',
      max: 19
    };
  }
  if (score > 19 && score <= 44) {
    rankOBj = {
      rank: 2,
      rankName: '大牌替身',
      max: 44
    }
  }
  if (score > 44 && score <= 69) {
    rankOBj = {
      rank: 3,
      rankName: '新晋主角',
      max: 69
    };
  }
  if (score > 69 && score <= 99) {
    rankOBj = {
      rank: 4,
      rankName: '超级巨星',
      max: 99
    };
  }
  if(score > 99) {
    rankOBj = {
      rank: 5,
      rankName: '电影教父',
      max: 1000000
    };
  }
  return rankOBj;
}

module.exports = {
  formatTime: formatTime,
  getRank: getRank
}
